package com.adv.crm.controller.utils;

import com.adv.crm.beans.AccountBean;
import com.adv.crm.beans.AccountQueryBean;
import com.adv.crm.beans.WarpExtendResponse;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 16978 on 2016/7/24.
 */
public class ControllerUtils {
    public static void filterResponse(WarpExtendResponse<List<AccountBean>> response, AccountQueryBean bean) {
        List<String> ids = bean.getAccountIds();
        List<String> names = bean.getAccountNames();
        List<AccountBean> accounts = response.getData();
        int accountSize = 0;
        if (accounts != null) {
            accountSize = accounts.size();
        }
        if (ids != null && ids.size() > 0 && accountSize < ids.size()) {
            List<String> temp = new ArrayList<String>(ids);
            for (int i = 0; i < accounts.size(); i++) {
                AccountBean accountBean = accounts.get(i);
                String accountId = accountBean.getAccountId();
                if (temp.contains(accountId)) {
                    temp.remove(accountId);
                }
            }
            response.setExt(temp);
            return;
        }

        if (names != null && names.size() > 0 && accountSize < names.size()) {
            List<String> temp = new ArrayList<String>(names);
            for (int i = 0; i < accounts.size(); i++) {
                AccountBean accountBean = accounts.get(i);
                String accountName = accountBean.getAccountName();
                if (temp.contains(accountName)) {
                    temp.remove(accountName);
                }
            }
            response.setExt(temp);
            return;
        }
    }
}
